#include <bits/stdc++.h>
using namespace std;



class Solution 
{
public:
    int maxProfit(vector<int>& prices) 
    {
        int minP = prices[0];
        int ans = 0;
        for (auto & t : prices)
        { 
            ans = max(ans, t  - minP);
            minP = min(minP, t);
        }
        return ans;
    }
};

